//
//  ReadyCountDownLayer.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/6/13.
//
//

#include "ReadyCountDownLayer.h"
#include "MyUtilities.h"

bool ReadyCountDownLayer::init(){
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    countDownLabel = CCLabelBMFont::create("3", "Info.fnt");
    countDownLabel->setAnchorPoint(ccp(0.5,0.5));
    countDownLabel->setPosition(ccp(winSize.width/2,winSize.height/2));
    countDownLabel->setScale((winSize.width*0.2f)/countDownLabel->getContentSize().height);
    this->addChild(countDownLabel);
    this->setVisible(false);
    timeRemaining = 3;
    return true;
}

void ReadyCountDownLayer::getReady(){
    this->setVisible(true);
    this->schedule(schedule_selector(ReadyCountDownLayer::onTickReady), 1);
    
}

void ReadyCountDownLayer::onTickReady(float dt){
    timeRemaining--;
    
    if(timeRemaining==0){
        this->unscheduleAllSelectors();
        scene->startGame();
        this->setVisible(false);
        timeRemaining=3;
    }
    countDownLabel->setString(MyUtilities::toString(timeRemaining));
}